var t = function(t) {
    return Object.keys(t).reduce(function(e, a) {
        return e + "".concat((n = a, n.replace(/([A-Z])/g, function(t, e) {
            return "-".concat(e.toLowerCase());
        })), ":").concat(t[a], ";");
        var n;
    }, "");
};

Component({
    properties: {
        data: {
            type: Array,
            default: []
        },
        purchasersCount: {
            type: Number,
            default: 0
        }
    },
    data: {
        trackStyle: "",
        curIndex: 0,
        firstItemStyle: "",
        secondItemStyle: "",
        wrapStyle: ""
    },
    attached: function() {
        var t = this;
        this.data.data.length > 2 && this.computeItemSize().then(function() {
            t.computeTrackStyle(0), t.computeFirstItemStyle(0), t.computeSecondItemStyle(0), 
            t.setTimer();
        });
    },
    methods: {
        computeItemSize: function() {
            var e = this;
            return new Promise(function(a) {
                wx.createSelectorQuery().in(e).select(".purchasers__item").boundingClientRect(function(n) {
                    e.itemHeight = n.height, e.setData({
                        wrapStyle: t({
                            maxHeight: 2 * e.itemHeight + "px"
                        })
                    }), a();
                }).exec();
            });
        },
        computeTrackStyle: function(e, a) {
            var n = -e * this.itemHeight + "px";
            a && (n = -this.data.data.length * this.itemHeight + "px");
            var i = {
                transform: "translateY(".concat(n, ")"),
                transitionDuration: "500ms"
            };
            this.setData({
                trackStyle: t(i)
            });
        },
        computeSecondItemStyle: function(e) {
            var a = e === this.data.data.length - 1 ? this.data.data.length * this.itemHeight + "px" : 0, n = {
                transform: "translateY(".concat(a, ")")
            };
            this.setData({
                secondItemStyle: t(n)
            });
        },
        computeFirstItemStyle: function(e) {
            var a = e === this.data.data.length - 2, n = e === this.data.data.length - 1, i = a || n ? this.itemHeight * this.data.data.length + "px" : 0, r = {
                transform: "translateY(".concat(i, ")")
            };
            this.setData({
                firstItemStyle: t(r)
            });
        },
        setTimer: function() {
            var t = this;
            this.timer = setInterval(function() {
                t.move(1);
            }, 2e3);
        },
        move: function(e) {
            var a = this, n = this.data.curIndex, i = n + e, r = n === this.data.data.length - 1;
            0 === n ? this.setData({
                trackStyle: t({
                    transitionDuration: 0,
                    transform: "translateY(0)"
                }),
                firstItemStyle: t({
                    transform: "translateY(0)"
                }),
                secondItemStyle: t({
                    transform: "translateY(0)"
                })
            }, function() {
                i = r ? 0 : i, a.computeFirstItemStyle(n), a.computeSecondItemStyle(n), a.computeTrackStyle(i, r), 
                a.setData({
                    curIndex: i
                });
            }) : (i = r ? 0 : i, this.computeFirstItemStyle(n), this.computeSecondItemStyle(n), 
            this.computeTrackStyle(i, r), this.setData({
                curIndex: i
            }));
        }
    }
});